// 接口名字由方法名加er后缀组成
package main

import "fmt"

// 定义接口
type Shaper interface {
	Area() float32
}

type Square struct {
	side float32
}

// 定义方法
func (sq *Square) Area() float32 {
	return sq.side * sq.side
}

// 多态
type Rectangle struct {
	length, width float32
}

func (r Rectangle) Area() float32 {
	return r.length * r.width
}

func main() {
	sq1 := new(Square)
	sq1.side = 5

	var areaIntf Shaper
	areaIntf = sq1
	fmt.Printf("The square has area: %f\n", areaIntf.Area())

	//多态
	r := Rectangle{5, 3}
	q := &Square{5}
	shapes := []Shaper{r, q}
	fmt.Println("shapes:", shapes)
	for n, _ := range shapes {
		fmt.Println("Shape details: ", shapes[n])
		fmt.Println("Area of this shape is: ", shapes[n].Area())
	}
}
